﻿@using UHub.Web.Models.Client

@{
	string[] allGrantTypes = (string[])ViewData["AllGrantTypes"];
	string[] allScopes = (string[])ViewData["AllScopes"];
}

<div class="card">
	<div class="card-body">
		<div class="btn-group">
			<a type="button" class="btn btn-secondary" asp-controller="Client" asp-action="Index">返回</a>
			<button id="js-btn-save" onclick="saveData()" class="btn btn-primary">保存</button>
		</div>
		<form id="js-form">
			<div class="form-group row">
				<label class="col-sm-3 col-form-label">ClientId</label>
				<div class="col-sm-9">
					<input name="ClientId" type="text" class="form-control">
				</div>
			</div>
			<div class="form-group row">
				<label class="col-sm-3 col-form-label">ClientSecret</label>
				<div class="col-sm-9">
					<input name="ClientSecret" type="text" class="form-control">
				</div>
			</div>
			<div class="form-group row">
				<label class="col-sm-3 col-form-label">显示名</label>
				<div class="col-sm-9">
					<input name="DisplayName" type="text" class="form-control">
				</div>
			</div>
			<div class="form-group row">
				<label class="col-sm-3 col-form-label">描述</label>
				<div class="col-sm-9">
					<input name="Description" type="text" class="form-control">
				</div>
			</div>
			<div class="form-group">
				<label>授权类型</label>
				<select name="AllowedGrantTypes" class="form-control">
					@foreach (var item in allGrantTypes)
					{
						<option value="@item">@item</option>
					}
				</select>
			</div>
			<div class="form-group">
				<label>允许范围</label>
				<div>参考: @string.Join(",", allScopes)</div>
				<textarea name="AllowedScopes" class="form-control" rows="3" placeholder="多个之间用,隔开"></textarea>
			</div>
			<div class="form-group">
				<label>跨域白名单</label>
				<textarea name="AllowedCorsOrigins" class="form-control" rows="3" placeholder="多个之间用,隔开"></textarea>
			</div>
			<div class="form-group">
				<label>登录回调地址</label>
				<textarea name="RedirectUris" class="form-control" rows="3" placeholder="多个之间用,隔开"></textarea>
			</div>
			<div class="form-group">
				<label>登出回调地址</label>
				<textarea name="PostLogoutRedirectUris" class="form-control" rows="3" placeholder="多个之间用,隔开"></textarea>
			</div>
			<div class="form-group row">
				<label class="col-sm-3 col-form-label">需要同意授权</label>
				<select name="RequireConsent" class="form-control">
					<option value="True">是</option>
					<option value="False">否</option>
				</select>
			</div>
			<div class="form-group row">
				<label class="col-sm-3 col-form-label">允许AccessToken经由浏览器传输</label>
				<select name="AllowAccessTokensViaBrowser" class="form-control">
					<option value="True">是</option>
					<option value="False">否</option>
				</select>
			</div>
			<div class="form-group row">
				<label class="col-sm-3 col-form-label">总是包含UserClaims在IdToken中</label>
				<select name="AlwaysIncludeUserClaimsInIdToken" class="form-control">
					<option value="True">是</option>
					<option value="False">否</option>
				</select>
			</div>
			<div class="form-group row">
				<label class="col-sm-3 col-form-label">需要RefreshToken</label>
				<select name="AllowOfflineAccess" class="form-control">
					<option value="True">是</option>
					<option value="False">否</option>
				</select>
			</div>
		</form>
	</div>
</div>
@section scripts
{
	<script>
		function saveDataSuccess(data) {
			if (data.code <= 0) {
				showMessage(data.message, -1);
			} else {
				showMessage(data.message, 1);
			}
			$("#js-btn-save").html("保存").removeAttr("disabled");
		}

		function saveData() {
			$("#js-btn-save").html("保存中").attr("disabled", "disabled");
			$.ajax({
				url: "/Client/Create",
				type: "post",
				dataType: "json",
				data: $("#js-form").serialize(),
				success: saveDataSuccess
			});
			return false;
		}
	</script>
}
